package productos;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import org.junit.Before;
import org.junit.Test;

import envio.Envio;

public class TestStock {

	Stock stock;
	Envio envio;

	@Before
	public void setUp() throws Exception {
		envio = mock(Envio.class);
	}

	@Test
	public void testInstancioUnStockYVerificoQueSusVariablesSeInicialicenCorrectamente() {
		stock = new Stock(100, 50, 40);
		assertNotNull(stock.getCantidadStock());
	}

	@Test
	public void testCreoUnStockConCantidadMayorAlStockCritico() {
		stock = new Stock(100, 50, 40);
		assertFalse(stock.porDebajoStockCritico());
	}

	@Test
	public void testCreoUnStockConCantidadMenorAlStockCritico() {
		stock = new Stock(10, 50, 40);
		assertTrue(stock.porDebajoStockCritico());
	}

	@Test
	public void testCreoUnStockConCantidadMayorAlStockMinimo() {
		stock = new Stock(100, 50, 40);
		assertFalse(stock.porDebajoStockMinimo());
	}

	@Test
	public void testCreoUnStockConCantidadMenorAlStockMinimo() {
		stock = new Stock(10, 50, 40);
		assertTrue(stock.porDebajoStockMinimo());
	}
	
	@Test
	public void testAgregoUnEnvioComoObservadorALaListaDeObservadores(){
		stock = new Stock(100, 50, 40);
		stock.agregarEnvioObservador(envio);
		assertNotNull(stock.enviosSuscriptos);
	}

	@Test
	public void testCheckeoQueSeRecorraLaListaDeEnviosSuscriptosACambiosDeStock() {
		stock = new Stock(100, 50, 40);
		when(envio.checkEnvioPosible()).thenReturn(true);
		stock.agregarEnvioObservador(envio);
		stock.notificarCambiosAEnvios();
		verify(envio, times(1)).checkEnvioPosible();
		verify(envio, times(1)).avisarACliente();
	}

}
